package cn.edu.dyxy.controller;

import cn.edu.dyxy.entity.CartItem;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

/**
 * @author JokerQiu
 * @date 2021年12月25日 10:21
 */
@WebServlet("/deleteBook")
public class DeleteBookServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("DeleteBookServlet");
        /**
         * 获取数据
         * 删除数据
         * 返回结果
         */
        String bookId = req.getParameter("bookId");
        System.out.println(bookId);
        HttpSession session = req.getSession();
        Map<String, CartItem> cart =
                (Map<String, CartItem>) session.getAttribute("cart");
        cart.remove(bookId);
        resp.getWriter().write("删除成功");
    }
}
